import React, {Component} from 'react';

/**
 * 子组件的定义
 *
 * handleItemDelete 接收父组件参数
 *
 * const {key,key} = this.props //解构赋值
 */

class TodoItem extends Component {

    constructor(props) {
        super(props)
        this.handleItemDelete = this.handleItemDelete.bind(this);
    }

    render() {
        //this.props.content
        const {content} = this.props;
        return (
            <div onClick={this.handleItemDelete}>{content}</div>
        )
    }

    handleItemDelete() {
        const {deleteItem, position} = this.props;
        console.log('index =', position);
        deleteItem(position);
        // this.props.deleteItem(this.props.position); 等价于上面结构 {解构赋值}

        const {log} = console;
        let greeting = `\`Yo\` World!`;

        log(`${[[1, 2], [3, 4]].map(([a, b]) => a + b)}`);
        log(`${greeting}`);
    }
}

export default TodoItem;